#ifndef STUDENT_H_
#define STUDENT_H_

#include "Student.h"

void Add_student(string s, Student l[], int &numberStudent){
   string temp, a_fname, a_dob, a_addr, a_program, a_class;
   int a_id, a_year;

   int mark = s.find(":");
   a_id = atoi(s.substr(0,mark).c_str());


   temp = s.substr(mark+1);
   mark = temp.find(":");
   a_fname = temp.substr(0,mark);

   temp = temp.substr(mark+1);
   mark = temp.find(":");
   a_dob = temp.substr(0,mark);

   temp = temp.substr(mark+1);
   mark = temp.find(":");
   a_addr = temp.substr(0,mark);

   temp = temp.substr(mark+1);
   mark = temp.find(":");
   a_year = atoi(temp.substr(0,mark).c_str());

   temp = temp.substr(mark+1);
   mark = temp.find(":");
   a_program = temp.substr(0,mark);

   temp = temp.substr(mark+1);
   mark = temp.find(":");
   a_class = temp.substr(0,mark);

   Student stu(a_id, a_fname, a_dob, a_addr, a_year, a_program, a_class);
   l[numberStudent] = stu;
   numberStudent = numberStudent + 1;
}

void ReadFile(string _file, Student l[], int &numberStudent){
               ifstream fin;
               fin.open(_file.c_str());
               if(!fin.is_open()){
                       cout<<"Cannot open file.\n";
                       exit(1);
               }else{
                              string s = "";
                              while (getline(fin, s)){
                                Add_student(s,l,numberStudent);
                              }
                              fin.close();
               }
}

void WriteOutput(string _file, Student l[], int numberStudent){
               ofstream fout;
               fout.open(_file.c_str());
               for (int i=0 ; i<numberStudent ; i++){
                              fout<<l[i].get_id()<<":"<<l[i].get_fname()<<":"<<l[i].get_dob()<<":"<<l[i].get_addr()<<":"<<l[i].get_year()<<":"<<l[i].get_program()<<":"<<l[i].get_classname()<<endl;
               }
               fout.close();
}

#endif

